package com.yc.music.receiver;

import ohos.event.commonevent.CommonEventData;
import ohos.event.commonevent.CommonEventSubscribeInfo;
import ohos.event.commonevent.CommonEventSubscriber;
import ohos.event.commonevent.CommonEventSupport;

import com.yc.music.config.MusicConstant;
import com.yc.music.service.PlayService;
import com.yc.music.utils.MusicLogUtils;

/**
 * 屏幕亮了，灭了，弹出锁屏页面逻辑
 * 其实这个跟通知处理逻辑一样
 *
 * @since 2021-05-10
 */
public class AudioBroadcastReceiver extends CommonEventSubscriber {
    /**
     * 构造函数
     *
     * @param subscribeInfo subscribeInfo
     */
    public AudioBroadcastReceiver(CommonEventSubscribeInfo subscribeInfo) {
        super(subscribeInfo);
    }

    @Override
    public void onReceiveEvent(CommonEventData commonEventData) {
        final String action = commonEventData.getIntent().getAction();
        if (action != null && action.length() > 0) {
            PlayService playService = new PlayService();
            switch (action) {
                // 锁屏时处理的逻辑
                case MusicConstant.LOCK_SCREEN_ACTION:
                    playService.startCommand(MusicConstant.LOCK_SCREEN_ACTION);
                    MusicLogUtils.e("AudioBroadcastReceiver" + "---LOCK_SCREEN");
                    break;
                // 当屏幕灭了
                case CommonEventSupport.COMMON_EVENT_SCREEN_OFF:
                    playService.startCommand(CommonEventSupport.COMMON_EVENT_SCREEN_OFF);
                    MusicLogUtils.e("AudioBroadcastReceiver" + "---当屏幕灭了");
                    break;
                // 当屏幕亮了
                case CommonEventSupport.COMMON_EVENT_SCREEN_ON:
                    playService.startCommand(CommonEventSupport.COMMON_EVENT_SCREEN_ON);
                    MusicLogUtils.e("AudioBroadcastReceiver" + "---当屏幕亮了");
                    break;
                default:
                    break;
            }
        }
    }
}
